//
//  HomeViewController.swift
//  Example
//
//  Created by xx on 2025/3/17.
//

import UIKit
import FastSwiftSDK

class TestHomeViewController: FastViewController,UITableViewDelegate,UITableViewDataSource {
    
    // MARK: - Data
    let listData:Array<Dictionary<String,Any>> = [["title":"超声波测油仪","vc":DistanceViewViewController()],
                                                  ["title":"转向舵机","vc":DistanceViewViewController()],
                                                  ["title":"雷达","vc":RadarViewController()],
                                                  ["title":"通用测试","vc":DefaultTestViewController()],
                                                  ["title":"小船项目","vc":BoatViewController()],
                                                  ["title":"中控台","vc":MainViewViewController()],
    ]
    
    
    private lazy var tableView : UITableView = {
        let view =  UITableView.init(frame: .zero, style: .plain)
        view.delegate = self
        view.dataSource = self
        self.view.addSubview(view)
        return  view
    } ()
    
    private lazy var logoView : LogoView = {
        let view =  LogoView()
        self.view.addSubview(view)
        return view
    } ()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "首页"
        
      
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        XXDeviceManager.shared.refresh()
    }
    
    override func viewWillLayoutSubviews() {
        self.tableView.snp.makeConstraints { make in
            make.top.equalTo(kNavH)
            make.left.bottom.right.equalToSuperview()
        }
        self.logoView.snp.makeConstraints { make in
            make.left.bottom.equalToSuperview()
            make.width.equalTo(150)
            make.height.equalTo(80)
        }
    }
    
    // MARK: - tableDelegate
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return listData.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        let data = listData[indexPath.row]
        cell.textLabel?.text = data["title"] as! String
        cell.accessoryType = .disclosureIndicator
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let data = listData[indexPath.row]
        let vc = data["vc"] as! UIViewController
        self.push(vc)
        
        
    }


}
